// DlgCfgCoordinate.cpp : implementation file
//

#include "stdafx.h"
#include "DlgCfgCoordinate.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgCfgCoordinate dialog


CDlgCfgCoordinate::CDlgCfgCoordinate(CWnd* pParent /*=NULL*/)
	: CDialogEx(CDlgCfgCoordinate::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgCfgCoordinate)
	m_CoordianateOrg = -1;
	//}}AFX_DATA_INIT
}


void CDlgCfgCoordinate::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgCfgCoordinate)
	DDX_Radio(pDX, IDC_RADIO_LEFTTOP, m_CoordianateOrg);
	DDX_Radio(pDX, IDC_RADIO_LEFTTOPGRAPH, m_MoveReturnOrg);
	DDX_Radio(pDX, IDC_RADIO_ZUp, m_ZMoveReturnOrg);
	
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgCfgCoordinate, CDialogEx)
	//{{AFX_MSG_MAP(CDlgCfgCoordinate)
	ON_EN_CHANGE(IDC_EDIT_TABLEX, OnChangeEditTablex)
	ON_EN_CHANGE(IDC_EDIT_TABLEY, OnChangeEditTabley)
	ON_EN_CHANGE(IDC_EDIT_TABLEZ, OnChangeEditTablez)
	ON_EN_CHANGE(IDC_EDIT_HorPasteMove, OnChangeEditHorPasteMove)
	ON_EN_CHANGE(IDC_EDIT_VelPasteMove, OnChangeEditVelPasteMove)
	ON_EN_CHANGE(IDC_EDIT_MINLEN, OnChangeEditMinLen)
	
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgCfgCoordinate message handlers

void CDlgCfgCoordinate::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData();
	CString strTemp;
	GetDlgItemText(IDC_EDIT_TABLEX,strTemp);
	double dTableX = CTool::CStringToDouble(strTemp);
	((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dAxisX = dTableX;
	GetDlgItemText(IDC_EDIT_TABLEY,strTemp);
	double dTableY = CTool::CStringToDouble(strTemp);
	((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dAxisY = dTableY;
	GetDlgItemText(IDC_EDIT_TABLEZ,strTemp);
	double dTableZ = CTool::CStringToDouble(strTemp);
	((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dAxisZ = dTableZ;

	((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_iOrgPos = m_CoordianateOrg;
// 	((CDlgSysParam*)GetParent())->m_param.m_movePara.m_iOrgReturnOrg = m_MoveReturnOrg;
// 	((CDlgSysParam*)GetParent())->m_param.m_movePara.m_iOrgReturnOrg = m_ZMoveReturnOrg;
	
	if (CDlgLogin::gAuthority > 1)
	{
		GetDlgItem(IDC_EDIT_TABLEX)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_TABLEY)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_TABLEZ)->EnableWindow(FALSE);
	}
	else
	{
		GetDlgItem(IDC_EDIT_TABLEX)->EnableWindow();
		GetDlgItem(IDC_EDIT_TABLEY)->EnableWindow();
		GetDlgItem(IDC_EDIT_TABLEZ)->EnableWindow();
	}

	if (((CButton*)GetDlgItem(IDC_CHECK_EnableShowPos))->GetCheck())
	{
		((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_iEnableShowLivePos=1;
	}
	else
	{
		((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_iEnableShowLivePos=0;
	}

	CDialogEx::OnOK();
}

BOOL CDlgCfgCoordinate::OnInitDialog() 
{
	CDialogEx::OnInitDialog();
	
	// TODO: Add extra initialization here
	//gRWOperate.ReadKey(_T("CoordinateSys"),_T("OrgPos"),m_CoordianateOrg);
	m_CoordianateOrg = ((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_iOrgPos;
// 	m_MoveReturnOrg = ((CDlgSysParam*)GetParent())->m_param.m_movePara.m_iOrgReturnOrg;
// 	m_ZMoveReturnOrg = ((CDlgSysParam*)GetParent())->m_param.m_movePara.m_iOrgReturnOrgZ;
	CString strTemp;
	strTemp.Format(_T("%.5f"),((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dAxisX);
	SetDlgItemText(IDC_EDIT_TABLEX,strTemp);
	
	strTemp.Format(_T("%.5f"),((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dAxisY);
	SetDlgItemText(IDC_EDIT_TABLEY,strTemp);
	
	strTemp.Format(_T("%.5f"),((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dAxisZ);
	SetDlgItemText(IDC_EDIT_TABLEZ,strTemp);

	UpdateData(FALSE);

	if (CDlgLogin::gAuthority > 1)
	{
		GetDlgItem(IDC_EDIT_TABLEZ)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_TABLEX)->EnableWindow(FALSE);
		GetDlgItem(IDC_EDIT_TABLEY)->EnableWindow(FALSE);
	}
	else
	{
		GetDlgItem(IDC_EDIT_TABLEZ)->EnableWindow();
		GetDlgItem(IDC_EDIT_TABLEX)->EnableWindow();
		GetDlgItem(IDC_EDIT_TABLEY)->EnableWindow();
	}
	if ( ((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_iEnableShowLivePos == 1)
	{
		((CButton*)GetDlgItem(IDC_CHECK_EnableShowPos))->SetCheck(1);
	}
	else
	{
		((CButton*)GetDlgItem(IDC_CHECK_EnableShowPos))->SetCheck(0);
	}
	strTemp.Format(_T("%.5f"),((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dHorPasteMove);
	SetDlgItemText(IDC_EDIT_HorPasteMove,strTemp);

	strTemp.Format(_T("%.5f"),((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dVelPasteMove);
	SetDlgItemText(IDC_EDIT_VelPasteMove,strTemp);

	strTemp.Format(_T("%.5f"),((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dMinLen);
	SetDlgItemText(IDC_EDIT_MINLEN,strTemp);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgCfgCoordinate::OnChangeEditTablex() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialogEx::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CString strTemp;
	GetDlgItemText(IDC_EDIT_TABLEX,strTemp);
	double dTableX = CTool::CStringToDouble(strTemp);
	((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dAxisX = dTableX;
}

void CDlgCfgCoordinate::OnChangeEditTabley() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialogEx::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CString strTemp;
	GetDlgItemText(IDC_EDIT_TABLEY,strTemp);
	double dTableY = CTool::CStringToDouble(strTemp);
	((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dAxisY = dTableY;
}


void CDlgCfgCoordinate::OnChangeEditTablez() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialogEx::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CString strTemp;
	GetDlgItemText(IDC_EDIT_TABLEZ,strTemp);
	double dTableZ = CTool::CStringToDouble(strTemp);
	((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dAxisZ = dTableZ;
}

void CDlgCfgCoordinate::OnChangeEditHorPasteMove() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialogEx::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strTemp;
	GetDlgItemText(IDC_EDIT_HorPasteMove,strTemp);
	double dHorPasteMove = CTool::CStringToDouble(strTemp);
	((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dHorPasteMove = dHorPasteMove;
}

void CDlgCfgCoordinate::OnChangeEditVelPasteMove() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialogEx::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strTemp;
	GetDlgItemText(IDC_EDIT_VelPasteMove,strTemp);
	double dVelPasteMove = CTool::CStringToDouble(strTemp);
	((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dVelPasteMove = dVelPasteMove;
}

void CDlgCfgCoordinate::OnChangeEditMinLen() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialogEx::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO: Add your control notification handler code here
	CString strTemp;
	GetDlgItemText(IDC_EDIT_MINLEN,strTemp);
	double dMinLen = CTool::CStringToDouble(strTemp);
	((CDlgSysParam*)GetParent())->m_param.m_viewPara.m_dMinLen = dMinLen;
}
